import { initState } from "./store";
import { State, Action } from "./type";
import { Reducer } from "redux";

export const reducer: Reducer<State, Action> = (state = initState, action) => {
  switch (action.type) {
    case "increment":
      return { ...state, count: state.count + 1 };
    case "decrement":
      return { ...state, count: state.count - 1 };
    case "changeName":
      return { ...state, name: action.payload?.name || "" };
    default:
      return state;
  }
};